#include "StdAfx.h"


trianList   TriangleFactory::m_triangleList;
long double TriangleFactory::m_area;

TriangleFactory::TriangleFactory(void)
{
}

TriangleFactory::~TriangleFactory(void)
{
}

void TriangleFactory::AddTriangle(const Triangle & t)
{
  m_triangleList.push_back(t);
}

void TriangleFactory::DrawAll(const HWND & hwnd, const POINT & shift)
{
  Triangle t;
  trianIter it;

  for(it = m_triangleList.begin();
      it != m_triangleList.end();
      it++)
  {
    t = *it;
    t.Draw(hwnd, shift);
  }
}

void TriangleFactory::Clear()
{
  m_triangleList.clear();
}

const long double & TriangleFactory::CalculateField(int scale, int x_resolution, int y_resolution)
{
  m_area = 0.0f;
  Triangle t;
  trianIter it;
  TCHAR text[200];
  int size = 0; 

  m_area = 0.0;

  for(it = m_triangleList.begin();
      it != m_triangleList.end();
      it++)
  {
    t = *it;
    m_area += t.Area(x_resolution, y_resolution);
    /*
    strcpy(text,"XDPI:");
    size = strlen(text);
    itoa(x_resolution, &text[size], 10);
    size = strlen(text);
    strcpy(&text[size],"YDPI:");
    size = strlen(text);
    itoa(y_resolution, &text[size], 10);
    size = strlen(text);
    strcpy(&text[size],"SCALE:");
    size = strlen(text);
    itoa(scale, &text[size], 10);
    size = strlen(text);
    _gcvt_s(&text[size], 100, m_area,10);
    MessageBox(NULL, text, "info",MB_OK); */
  }
  //Now we have a sum of all triangles' areas in square inches
  //Lets recalculate to ACRE and upscale

  m_area = m_area * ( pow((double)scale,2)); //upscale

  m_area = m_area / ACRE_SQUARE_INCH; //Now we have an area in acre

  //_gcvt_s(text, 200, m_area,4);
  //MessageBox(NULL, text,"InfoT" , MB_OK | MB_ICONINFORMATION | MB_TASKMODAL | MB_DEFBUTTON1);
  
  return(m_area);
}